<?php
require_once APP . '/application/controllers/FrontAction.php';
require_once APP . '/application/models/Article.php';

/**
 * 文章
 */
class ArticleController extends FrontAction
{
    /**
     * 本controller通用模块
     */
    public function init ()
    {
    }
    
    
    /**
     * 首页
     *
     */
    public function indexAction()
    {
    }
    
    /**
     * 列表页面
     *
     */
    public function listAction()
    {
    	$id = (int)$_REQUEST['id'];
    	
    	$typename = "";
    	foreach ($this->cfg['article_types'] as $v){
    		if ($v['id'] == $id)
    			$typename = $v['name'];
    	}
    	
    	$nowp = intval($this->getParam("nowp", 1));
    	
    	// 读取文章列表
    	$obj_article = new Article($this->db);
    	$result = $obj_article->listArticle($id, $nowp, 15);
    	
    	$this->view->list = $result['list'];
    	$this->view->page = $result['page'];
    	$this->view->pagenum = Util::pageNumStyle($result['page']);
    	
    	$this->view->typeid = $id;
    	$this->view->typename = $typename;
    	$this->view->htitle = $typename;
    	
    	$this->render("list");
    }
    
    /**
     * 显示页面
     *
     */
    public function showAction()
    {
    	$id = (int)$_REQUEST['id'];
    	    	
    	// 获取该分类的文章
    	$obj_article = new Article($this->db);
    	$arr_articleinfo = $obj_article->show($id);
    	$cid = $arr_articleinfo['cid'];
    	
    	$typename = "";
    	foreach ($this->cfg['article_types'] as $v){
    		if ($v['id'] == $cid)
    			$typename = $v['name'];
    	}
    	    	
    	$this->view->typeid = $cid;
    	$this->view->typename = $typename;
    	$this->view->content = $arr_articleinfo;
    	$this->view->htitle = htmlspecialchars($arr_articleinfo['title']);
    	
    	$this->render("show");
    	
    }
}
